package dkbta.ontology.values;

import java.util.List;

/**
 * A set of symbolic values (Strings)
 * 
 * @author Uri Kanonov
 */
public class SymbolicValues implements Values{
	/** The possible values */
	private final List<String> _possibleValues;

	public SymbolicValues(List<String> possibleValues){
		_possibleValues = possibleValues;
	}

	/**
	 * Returns the type of value the implementation represents
	 * 
	 * @return the type of value the implementation represents
	 */
	public ValuesType getValueType(){
		return ValuesType.SYMBOLIC;
	}

	/**
	 * Returns a string representation of the values
	 * 
	 * @return A string representation of the values
	 */
	@Override
	public String toString(){
		return _possibleValues.toString();
	}

	/**
	 * Checks whether the given value (in string form) fits into the possible values,
	 * parses it accordingly and returns it. Returns null if the value wasn't valid.
	 * 
	 * @param value The tested value
	 * @return The parsed value according to the values object or null if the value wasn't
	 *         valid.
	 */
	public String parseAndValidate(String value){
		if (_possibleValues.contains(value)){
			return value;
		}else{
			return null;
		}
	}

	/**
	 * Checks whether the given value (already parsed) fits into the possible values
	 * 
	 * @param valueType The type of the value
	 * @param value The value
	 * @return Whether the given value fits into the possible values
	 */
	public boolean isValid(ValuesType valueType, Object value){
		if (valueType == getValueType()){
			return _possibleValues.contains(value);
		}else{
			return false;
		}
	}

	@Override
	public boolean contains(Values v){
		if (v instanceof SymbolicValues){
			SymbolicValues o = (SymbolicValues)v;
			return _possibleValues.containsAll(o._possibleValues);
		}
		return false;
	}
}
